/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.util.xml;

import java.util.Enumeration;
import java.util.Hashtable;
/*
 *
 * */

/**
 *@author Alejandro Riveros Cruz Riveros Cruz
 *@version DocumentXML.java,v 1 2008/20/03
 * */
public class TableDocument {

    /**
     *
     */
    private String name;
    /**
     *
     */
    private String rootName;
    /**
     *
     */
    private Hashtable<String, String> content;

    /**
     * @param:
     * @return:
     */
    public TableDocument() {
    }

    /**
     * @param:
     * @return:
     */
    public TableDocument(String name) {
        this.name = name;
        content = new Hashtable<String, String>();
    }

    /**
     * @param:
     * @return:
     * @Override
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param:
     * @return:
     * @Override
     */
    public String getName() {
        return name;
    }

    /**
     * @param:
     * @return:
     */
    public String getRootName() {
        return rootName;
    }

    /**
     * @param:
     * @return:
     */
    public void setRootName(String rootName) {
        this.rootName = rootName;
    }

    /**
     * @param:
     * @return:
     */
    public void setContent(Hashtable<String, String> con) {
        content = con;
    }

    /**
     * @param:
     * @return:
     */
    public Hashtable<String, String> getContent() {
        return content;
    }

    /**
     * @param:
     * @return:
     */
    public void addTagContent(String tag, String con) {
        content.put(tag.toLowerCase(), con);
    }

    /**
     * @param:
     * @return:
     */
    public void addContent(Hashtable<String, String> info) {
        String currentKey;
        for (Enumeration<String> keys = info.keys(); keys.hasMoreElements();) {
            currentKey = keys.nextElement();
            content.put(currentKey.toLowerCase(), info.get(currentKey));
        }
    }

    /**
     * @param:
     * @return:
     */
    public void addContentWithPrefix(String prefix, Hashtable<String, String> info) {
        String currentKey;
        for (Enumeration<String> keys = info.keys(); keys.hasMoreElements();) {
            currentKey = keys.nextElement();
            content.put((prefix + "-" +currentKey).toLowerCase(), info.get(currentKey));
        }
    }

    /**
     * @param:
     * @return:
     */
    public String getTagContent(String tag) {
        return content.get(tag.toLowerCase());
    }

    /**
     * @param:
     * @return:
     */
    public String getTagContent(String... tag) {
        StringBuffer currentContent = new StringBuffer();
        for (int i = 0; i < tag.length; i++) {
            currentContent.append(" " + content.get(tag[i].toLowerCase()));
        }
        return currentContent.toString();
    }

    /**
     * @param:
     * @return:
     * @Override
     */
    public String getCompleteContent() {
        String tempkey;
        StringBuffer currentContent = new StringBuffer();
        for (Enumeration<String> keys = content.keys(); keys.hasMoreElements();) {
            tempkey = keys.nextElement();
            currentContent.append(" " + content.get(tempkey));
        }
        return currentContent.toString();
    }

    /**
     * 
     */
    public void clearDocument() {
        name = "";
        content.clear();
    }
}
